package com.hqyj.controller;

import com.hqyj.pojo.Yan_addcustomerpojo;
import com.hqyj.pojo.Yan_liuyan;
import com.hqyj.service.service.LiuyanService;
import com.hqyj.service.service.YanAddCustomerService;
import com.hqyj.service.service.YanRemoveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/yanjie")
public class yanHoutaiController {
    // 返回点击新增后 打开一个新的页面
    @RequestMapping("/yanAddcustomer")
    public String yanAddCustomer(){return "/houtai/yanAddcustomer";}
    // 返回点击修改后，打开一个新的页面
    @RequestMapping("/yanUpdate")
    public String yanUpdate(){return "/houtai/yanUpdate";}


    @Autowired(required = false)
    LiuyanService liuyanService;
    @Autowired(required = false)
    YanRemoveService yanRemoveService;
    @Autowired(required = false)
    YanAddCustomerService yanAddCustomerService;
    // 获取留言
    @ResponseBody
    @RequestMapping("/dongtai")
    public List<Yan_liuyan> getDongtai(){
        return liuyanService.getDongtai();
    }

    // 处理账户的删除
    @ResponseBody
    @RequestMapping("/remove")
    public int remove(String userName){
        int data  = yanRemoveService.remove(userName);
        return data;
    }

    // 新增住户
    @ResponseBody
    @RequestMapping("/add")
    public int add(Yan_addcustomerpojo yan_addcustomerpojo){
        int data = yanAddCustomerService.add(yan_addcustomerpojo);
        return data;
    }

    // 查询住户 通过用户名
    @ResponseBody
    @RequestMapping("/search")
    public HashMap<String,Object> search(String userName){
        List<Yan_addcustomerpojo> list = yanAddCustomerService.search(userName);
        HashMap<String,Object> map = new HashMap<>();
        map.put("code",0);
        map.put("msg","");
        map.put("count",1);
        map.put("data",list);
        return map;
    }

    @ResponseBody
    @RequestMapping("/updateAccount")
//    public HashMap<String,Object> updateAccount(Yan_addcustomerpojo yan_addcustomerpojo){
//        HashMap<String,Object> map = new HashMap<>();
//        int data = yanAddCustomerService.updateAccount(yan_addcustomerpojo);
//        map.put("data",data);
//        return map;
//    }
    public int updateAccount(String userName, String address, String sex,String phone,String manager){
        int data = yanAddCustomerService.updateAccount(userName, address, sex, phone, manager);
        return data;
    }

    @ResponseBody
    @RequestMapping("/test")
    public int test(){
        int data = 1;

        return data;
    }


}
